﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebApplication6
{
    public partial class productlist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Labeltitle.Text = "商品列表";

            string sql = " select * from t_product where 1=1 order by id desc ";

            this.createlist(sql, Repeater1);





        }


        protected void createlist(string sql, Repeater repeater)
        {
            DataTable dt = SQLHelper.ExecuteDataTable(sql);


            //   数据源
            PagedDataSource Pgds = new PagedDataSource();
            //        



            Pgds.DataSource = dt.DefaultView;

            //        设置允许分页
            Pgds.AllowPaging = true;
            //        每页显示为10行
            Pgds.PageSize = 10;
            //        显示总共页数
            //
            lblTotalPage.Text = Pgds.PageCount.ToString();
            //        当前页
            int CurrentPage;
            //        请求页码为不为null设置当前页，否则为第一页
            if (Request.QueryString["Page"] != null)
            {

                CurrentPage = Convert.ToInt32(Request.QueryString["Page"]);
            }

            else
            {

                CurrentPage = 1;
            }
            //   当前页所引为页码-1
            Pgds.CurrentPageIndex = CurrentPage - 1;
            //   显示当前页码
            lblCurrentPage.Text = CurrentPage.ToString();
            //   如果不是第一页，通过参数Page设置上一页为当前页-1，否则不显示连接
            if (!Pgds.IsFirstPage)
            {
                //            Request.CurrentExecutionFilePath为当前请求虚拟路径
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1);
            }
            //        End If
            //   如果不是最后一页，通过参数Page设置下一页为当前页+1，否则不显示连接
            if (!Pgds.IsLastPage)
            {
                //    Request.CurrentExecutionFilePath为当前请求虚拟路径
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1);
            }
            //   模板绑定数据源  
            repeater.DataSource = Pgds;
            repeater.DataBind();

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sql = " select * from t_product where  1=1 ";


            if (spname.Text != null)
            {
                sql = sql + " and spname like '%" + spname.Text + "%' ";
            }
            if (fenlei.Text != null)
            {
                sql = sql + " and fenlei like '%" + fenlei.Text + "%' ";
            }

            sql = sql + " order by id desc ";

            this.createlist(sql, Repeater1);
        }
    }
}
